﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.APPModel.ParamModel;
using HCQ2_Model.VR.Params;
using HCQ2_Model.DocModel.APIResultModel;
using HCQ2_Model.DocModel.APIParam;
using System.Web;
using HCQ2_Model.WeiXinApiModel.ResultApiModel;
using HCQ2_Model.VLine.OutputDto;
using HCQ2_Model.VLine.Params;

namespace HCQ2_BLL
{
    public partial class T_VRExperienceRecordBLL: IT_VRExperienceRecordBLL
    {
        //******************************************pc*******************************************
        /// <summary>
        ///  获取体验记录列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<ExperienceRecord> GetRecordList(ExperRecordModel param)
        {
            List<T_VRExperienceRecord> list = DBSession.IT_VRExperienceRecordDAL.GetRecordList(param);
            if (list == null)
                return new List<ExperienceRecord>();
            return list.Select(s => s.ToPOCO())?.ToList();
        }
        /// <summary>
        ///  获取体验列表记录数量
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int GetRecordNumCount(ExperRecordModel param)
        {
            return DBSession.IT_VRExperienceRecordDAL.GetRecordNumCount(param);
        }
        /// <summary>
        ///  获取体验排行列表
        /// </summary>
        /// <param name="param">查询参数</param>
        /// <param name="total">返回记录数量</param>
        /// <returns></returns>
        public List<ExperienceRankModel> GetRecordRankList(ExperRecordModel param, string user_guid, out int total)
        {
            return DBSession.IT_VRExperienceRecordDAL.GetRecordRankList(param, user_guid, out total);
        }
        //******************************************接口*******************************************
        /// <summary>
        ///  获取体验记录列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<ExperienceRecord> GetRecordListByUser(QueryRecordModel model,int userId)
        {
            List<T_VRExperienceRecord> list = DBSession.IT_VRExperienceRecordDAL.GetRecordListByUser(model, userId);
            if (list == null)
                return new List<ExperienceRecord>();
            return list.Select(s => s.ToPOCO())?.ToList();
        }
        /// <summary>
        ///  获取体验排行：根据体验记录统计查询获得
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<ExperienceRankModel> GetPopularityRankList(QueryRecordModel model)
        {
            List<ExperienceRankModel> list = DBSession.IT_VRExperienceRecordDAL.GetPopularityRankList(model);
            if (list == null || list.Count <= 0)
                return null;
            list.ForEach(s =>
            {
                if(!string.IsNullOrEmpty(s.user_header))
                    s.user_header = s.user_header.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取个人成绩
        /// </summary>
        /// <param name="mdel"></param>
        /// <returns></returns>
        public List<UserScoreRankModel> GetScoreByUser(UserScoreParam model, int user_id)
        {
            return DBSession.IT_VRExperienceRecordDAL.GetScoreByUser(model, user_id);
        }
        /// <summary>
        ///  头记获取：比赛排名列表前10
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<GameRankModel> GetGameRankList(GameRank model, DateTime? in_date, DateTime? out_date)
        {
            string inDate = string.Empty, outDate = string.Empty;
            if (in_date != null)
                inDate = in_date.ToString();
            if (out_date != null)
                outDate = out_date.ToString();
            return DBSession.IT_VRExperienceRecordDAL.GetGameRankList(model, inDate, outDate);
        }
        /// <summary>
        ///  获取我的比赛排名站位
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> GetMyGameRank(MyGameRank model, int user_id, string in_date, string out_date)
        {
            return await DBSession.IT_VRExperienceRecordDAL.GetMyGameRank(model, user_id, in_date, out_date);
        }        
    }
}
